﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;

namespace SLControlLibrary.Demo
{
    public partial class DisplayCalendar : UserControl
    {
        public DisplayCalendar()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            sCntHeight.Value = 210;
            sCntWidth.Value = 210;

            List<Colors> _ColorList = new List<Colors>();
            Type colorType = typeof(System.Windows.Media.Colors);
            PropertyInfo[] piList = colorType.GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public);

            foreach (PropertyInfo pi in piList)
            {
                cbHeaderColor.Items.Add(pi.Name);
                cbWeekHeaderColor.Items.Add(pi.Name);
                cbViewBackgroundColor.Items.Add(pi.Name);
                cbMonthForeColor.Items.Add(pi.Name);
                cbYearForeColor.Items.Add(pi.Name);
                cbHeaderForeColor.Items.Add(pi.Name);
            }

            cbHeaderColor.SelectedItem = "Yellow";
            cbHeaderForeColor.SelectedItem = "Orange";
            cbWeekHeaderColor.SelectedItem = "Green";
            cbViewBackgroundColor.SelectedItem = "White";
            cbMonthForeColor.SelectedItem = "Blue";
            cbYearForeColor.SelectedItem = "Blue";

            TextBlock tb = new TextBlock();
            tb.Text = "<SLCalendar:ucCalendar x:Name=\"ccDisplay\"" + Environment.NewLine +
                      "Height=\"300\"" + Environment.NewLine +
                      "Width=\"300\"" + Environment.NewLine +
                      "DateView=\"Decade\"" + Environment.NewLine +
                      "BorderBrush=\"Black\"" + Environment.NewLine +
                      "VerticalAlignment=\"Top\"" + Environment.NewLine +
                      "HorizontalAlignment=\"Center\"" + Environment.NewLine +
                      "DisplayMode=\"Display\"" + Environment.NewLine +
                      "HeaderBackground=\"Black\"" + Environment.NewLine +
                      "WeekHeaderForeground=\"Black\"" + Environment.NewLine +
                      "YearForeground=\"Black\"" + Environment.NewLine +
                      "MonthForeground=\"Black\" />";

            TabItem ti = (TabItem)tcDisplay.Items[1];
            ti.Content = tb;

            TextBlock tb2 = new TextBlock();
            tb2.Text = "ucCalendar Calendar = new ucCalendar();" + Environment.NewLine +
                       "Calendar.Height = 300;" + Environment.NewLine +
                       "Calendar.Width = 300;" + Environment.NewLine +
                       "Calendar.DateView = SLControlLibrary.Resources.Controls.Calendar.Common.Enumerations.CurrentDateView.Month;" + Environment.NewLine +
                       "Calendar.BorderBrush = new SolidColorBrush(Colors.Black);" + Environment.NewLine +
                       "Calendar.BorderThickness = new Thickness(1);" + Environment.NewLine +
                       "Calendar.VerticalAlignment = VerticalAlignment.Top;" + Environment.NewLine +
                       "Calendar.DisplayMode = SLControlLibrary.Resources.Controls.Calendar.Common.Enumerations.DisplayMode.Display;" + Environment.NewLine +
                       "Calendar.HeaderBackground = new SolidColorBrush(Colors.Cyan);";



            TabItem ti2 = (TabItem)tcDisplay.Items[2];
            ti2.Content = tb2;
        }

        private void cbViewBackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LayoutRoot.Background = SLControlLibrary.Resources.Common.Utility.ConvertStringToColor(cbViewBackgroundColor.SelectedItem.ToString()); ;
        }

        private void cbDateView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbDateView != null)
            {
                ComboBoxItem _Item = (ComboBoxItem)cbDateView.SelectedItem;
                ccDisplay.DateView = (SLControlLibrary.Resources.Controls.Calendar.Common.Enumerations.CurrentDateView)(Enum.Parse(typeof(SLControlLibrary.Resources.Controls.Calendar.Common.Enumerations.CurrentDateView), _Item.Content.ToString(), false));
            }
        }

        private void cbAnimationType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbAnimationType != null)
            {
                ComboBoxItem _Item = (ComboBoxItem)cbAnimationType.SelectedItem;
                ccDisplay.AnimationType = (SLControlLibrary.Resources.Controls.Calendar.Common.Enumerations.AnimationType)(Enum.Parse(typeof(SLControlLibrary.Resources.Controls.Calendar.Common.Enumerations.AnimationType), _Item.Content.ToString(), false));
            }
        }

        private void sCntHeight_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (ccDisplay != null)
                ccDisplay.ControlHeight = e.NewValue;
        }

        private void sCntWidth_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (ccDisplay != null)
                ccDisplay.ControlWidth = e.NewValue;
        }
    }
}
